#include "texturadefondo.h"

namespace ui {
namespace tablero {

TexturaDeFondo::TexturaDeFondo() {
}

bool TexturaDeFondo::bCargar(string p_sArchivo) {

	this->m_pTexturaSurface = SDL_LoadBMP(p_sArchivo.c_str());
	bool t_b = false;

	if (this->m_pTexturaSurface) {

		glGenTextures(1, &this->m_wIDTextura);
		glBindTexture(GL_TEXTURE_2D, this->m_wIDTextura);
	
		//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

		//glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		//glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

		glTexImage2D( GL_TEXTURE_2D, 0, 3, this->m_pTexturaSurface->w, this->m_pTexturaSurface->h, 
			0, GL_BGR, GL_UNSIGNED_BYTE, this->m_pTexturaSurface->pixels);

		t_b = true;
	}

	return t_b;
}

TexturaDeFondo::~TexturaDeFondo() {
	glDeleteTextures(1, &this->m_wIDTextura);
	SDL_FreeSurface(this->m_pTexturaSurface);
}

int TexturaDeFondo::getAncho() {
	return this->m_pTexturaSurface->w;
}

int TexturaDeFondo::getAltura() {
	return this->m_pTexturaSurface->h;
}

}
}
